package pers.qianyu.month_202012.date_20201210;

import org.junit.*;

import java.util.*;

/**
 * [巧妙]
 * 78. 子集
 * https://leetcode-cn.com/problems/subsets/
 *
 * @author mizzle rain
 * @date 2020-12-10 17:07
 */
public class Subsets3 {
    /**
     * 迭代
     */
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        res.add(new ArrayList<>());
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            int size = res.size();
            for (int j = 0; j < size; j++) {
                List<Integer> list = new ArrayList<>(res.get(j));
                list.add(num);
                res.add(list);
            }
        }
        return res;
    }

    @Test
    public void test1() {
        int[] arr = {1, 2, 3};
        List<List<Integer>> result = new Subsets3().subsets(arr);
        result.forEach(System.out::println);
    }
}
